#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_btn_calc_clicked()
{
    bool okNum, okPrice;

    QString inNum = this->ui->le_num->text();
    QString inPrice = this->ui->le_price->text();

    int num = inNum.toInt(&okNum,10);
    double price = inPrice.toDouble(&okPrice);

    if(okNum == false || okPrice == false)
    {
        ui->le_sum->setText("输入无效");
    }
    else
    {
        double sum = num * price;
        QString outSum(QString::asprintf("%.2f",sum));
        ui->le_sum->setText(outSum);
    }
}

